﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GLYFrom.YHGL
{
    public partial class YH_SeleDele : Form
    {
        public YH_SeleDele()
        {
            InitializeComponent();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确定要删除吗？","提示",MessageBoxButtons.OKCancel)==DialogResult.OK)
            {
                int id = Convert.ToInt32(this.dataGrid_YH.SelectedRows[0].Cells["Colu_YHId"].Value);
                int sr = DBHelper.ZSG(string.Format("delete from T_YongHu where YHId='{0}'", id));
                if (sr > 0)
                {
                    MessageBox.Show("删除成功！");
                    DataTable table = DBHelper.select("select * from T_YongHu");
                    this.dataGrid_YH.DataSource = table;
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void YH_SeleDele_Load(object sender, EventArgs e)
        {

            this.dataGrid_YH.AutoGenerateColumns = false;
            DataTable table = DBHelper.select("select * from T_YongHu");
            this.dataGrid_YH.DataSource = table;
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(this.dataGrid_YH.SelectedRows[0].Cells["Colu_YHId"].Value);
            YH_update from = new YH_update(id);
            from.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Name = this.text_Name.Text.Trim();
            string Sex = this.comboBox_Sex.Text.Trim();
            string Id = this.text_Id.Text.Trim();
            string sql = "select * from T_YongHu where 1=1";
            if (Name.Length>0)
            {
                sql += string.Format("and Name like '%{0}%'",Name);
            }
            if (Id.Length > 0)
            {
                sql += string.Format("and YHId like '%{0}%'", Id);
            }
            if (Sex.Length > 0)
            {
                sql += string.Format("and Sex like '%{0}%'", Sex);
            }
            DataTable table = DBHelper.select(sql);
            this.dataGrid_YH.DataSource = null;
            this.dataGrid_YH.DataSource = table;
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataTable table = DBHelper.select("select * from T_YongHu");
            this.dataGrid_YH.DataSource = null;
            this.dataGrid_YH.DataSource = table;
        }
    }
}
